package com.esun.rabbit2.viewer.mainact.lotteryhallact.shuangseqiuagp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.Rect;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.view.animation.AnticipateOvershootInterpolator;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.config.Language;
import com.esun.model.CurrentLotteryNumInfo;
import com.esun.model.ShuangseqiuInfo;
import com.esun.model.UserInfo;
import com.esun.network.ConnectionChangeReceiver;
import com.esun.network.communicater.UserCommunicater;
import com.esun.rabbit2.communicaters.CurrentLotteryNumCommunicater;
import com.esun.rabbit2.communicaters.ShuangseqiuNormalBuyCommunicater;
import com.esun.rabbit2.communicaters.ShuangseqiuTraceExpectCommunicater;
import com.esun.rabbit2.viewer.LoginAct;
import com.esun.rabbit2.viewer.RegistAct;
import com.esun.rabbit2.viewer.WebViewActivity;
import com.esun.rabbit2.viewer.mainact.OptionAct;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.BallMenuBuilder;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.ShuangseqiuAgp;
import com.esun.rabbit2.viewer.mainact.mylotteryact.recharg.RechargeMenuPage;
import com.esun.ui.R;
import com.esun.util.LoginTimeControl;
import com.esun.util.LotteryUtils;
import com.esun.util.Vibrate;
import com.esun.util.ViewerUtil;
import com.esun.util.log.EDebug;
import com.esun.util.wheel.widget.NumericWheelAdapter;
import com.esun.util.wheel.widget.OnWheelChangedListener;
import com.esun.util.wheel.widget.OnWheelScrollListener;
import com.esun.util.wheel.widget.WheelView;

/**
 * @Title: ShuangseqiuChooseAct.java
 * @Package com.esun.rabbit2.viewer.mainact.lotteryhallact.shuangseqiuagp
 * @Description: (双色球选号Activity)
 * @author City jiangsy@500wan.com
 * @date 2011-5-26 上午10:19:23 copy right 深圳市易讯天空网络技术有限公司
 */
@SuppressWarnings("deprecation")
public class ShuangseqiuChooseAct extends Activity implements OnClickListener, SensorListener {
	/** Called when the activity is first created. */

	private View chooseView; // 选球界面
	private View lotteryListView; // 列表界面
	private BallMenuBuilder ballMenuBuilderBlue; // 蓝球菜单
	private BallMenuBuilder ballMenuBuilderRed; // 红球菜单
	private LinearLayout linearBallMenuBlue; // 承载菜单的layout
	private LinearLayout linearBallMenuRed; // 承载菜单的layout
	private TextView tvBetNum; // 注数
	private TextView tvMoney; // 金额

	private Button btnCancel; // 放弃
	private Button btnClean; // 清空
	private Button btnRandom; // 随机
	private Button btnSubmit; // 确定选号
	private Button btnRedRandom; // 红球随机
	private Button btnBlueRandom; // 蓝球随机

	private Button btnListClean; // 清空列表
	private Button btnListCancel; // 返回选球
	private Button btnListAdd; // 添加单注随机投注
	private Button btnListHemai; // 发起合买
	private Button btnListSubmit; // 确认投注
	private TextView tvListBetCount; // 列表注数
	private TextView tvListMoney; // 列表金额
	private LinearLayout linearListSpace;
	private View.OnClickListener listenerListItem;

	private int betCountAll = 0; // 总注数
	private int moneyAll = 0; // 总金额
	public static int showType = 0;

	public static boolean isChooseView = true;
	private int listTagShow = -1;
	private int pageTag;

	/************************* 1.6.0 kael添加 **********************/
	/** 记录机选注数 */
	private int randomZhuShu = 0;
	/** 记录机选红球个数 */
	private int randomRedBallNum = 0;
	/** 记录机选篮球个数 */
	private int randomBlueBallNum = 0;
	/** 上期中奖号码按钮 */
	private Button btnLastLotteryNum;
	/** 显示中奖号码TextView所在的LinearLayout */
	private LinearLayout llLastLotteryNum;
	/** 显示上期中奖号码红色号码的TextView */
	private TextView tvLastLotteryNumRed;
	/** 显示上期中奖号码蓝色号码的TextView */
	private TextView tvLastLotteryNumBlue;
	/** 承载加载上期中奖号码ProgressBar的LinearLayout */
	private LinearLayout llLastLotteryNumProgress;
	/** 上期中奖号码红球 */
	private String redcode;
	/** 上期中奖号码篮球 */
	private String bluecode;
	/** 显示“加载失败”的LinearLayout */
	private LinearLayout llLastLotteryNumShibai;
	/** 机选红球个数选择菜单按钮 */
	private LinearLayout btnRedRandomNum;
	/** 显示机选红球个数的TextView */
	private TextView tvRedRandomNum;
	/** 机选蓝球个数选择菜单按钮 */
	private LinearLayout btnBlueRandomNum;
	/** 显示机选蓝球个数的TextView */
	private TextView tvBlueRandomNum;
	/** 显示机选红球个数按钮上的箭头 */
	private ImageView ivRedRandomNum;
	/** 显示机选蓝球个数按钮上的箭头 */
	private ImageView ivBlueRandomNum;
	/** 标记点击的是选择机选篮球个数的按钮 */
	private final static int RANDOMBLUEBALLTAG = 1;
	/** 标记点击的是选择机选红球个数的按钮 */
	private final static int RANDOMREDBALLTAG = 2;
	/** 判断点击的是选择哪种球机选个数的按钮，以便randomRedBallNum、randomBlueBallNum的赋值 */
	private int randomNumTag;
	/** 机选个数dialog适配器 */
	private ShowRandomNumDialogAdapter showRandomNumDialogAdapter;
	/** 机选红球个数选择Dialog */
	private Dialog dialogRed;
	/** 机选篮球个数选择Dialog */
	private Dialog dialogBlue;
	/** 判断是否点击dialog内部button导致dialog消失的还是按返回键dialog才消失的 */
	private boolean isClicked = false;
	/** 存放机选蓝球个数的ArrayList */
	private ArrayList<Hashtable<String, Object>> arrBlueBallNum;
	/** 存放机选红球个数的ArrayList */
	private ArrayList<Hashtable<String, Object>> arrRedBallNum;
	/** 存放倍投倍数的ArrayList 1~50 */
	private ArrayList<String> beishuNum;
	/** 存放追号期数的ArrayList 1~30 */
	private ArrayList<String> zhuihaoNum;
	/** 用户合同代购协议 */
	private LinearLayout btnUserAgreement;
	/** 设置倍投追号 */
	private LinearLayout llSetBeitouZhuihao;
	/** 选号列表显示倍数的TextView */
	private TextView tvListBeiShu;
	/** 选号列表显示追号期数的TextView */
	private TextView tvListZhuiHao;
	/** 显示倍投追号的Dialog */
	private Dialog beiTouZhuihaoDialog;
	/** 倍投滚轮 */
	private WheelView beishuWheel;
	/** 追号滚轮 */
	private WheelView zhuihaoWheel;
	/** 判断滚轮是否在滚动 */
	private boolean wheelScrolled = false;
	/** 滚轮当前位置的倍投 */
	private String beishuCurrent = Config.NUM1;
	/** 滚轮当前位置的追号 */
	private String zhuihaoCurrent = Config.NUM1;
	/** 点击确定按钮后的倍投 */
	private String beishuEnd = Config.NUM1;
	/** 点击确定按钮后的追号 */
	private String zhuihaoEnd = Config.NUM1;
	/** 设置倍投追号Dialog上完成按钮 */
	private Button btnDialogFinish;
	/** 设置倍投追号Dialog上取消按钮 */
	private Button btnDialogCancel;
	/** 中奖后停止追号的CheckBox */
	private CheckBox cbDialogStop;
	/** 确认提交订单的Dialog */
	private Dialog submitOrderDialog;
	/** 确认提交订单按钮 */
	private Button btnSubmitOrder;
	/** 取消提交订单按钮 */
	private Button btnCancelOrder;
	/** 购彩接口 */
	private ShuangseqiuNormalBuyCommunicater shuangseqiuNormalBuyCommunicater;
	/** 双色球追号期号列表接口 */
	private ShuangseqiuTraceExpectCommunicater expectCommuniacter;
	/** 用户信息接口 */
	UserCommunicater userCommunicater;
	/** 获取当期中奖号码接口 */
	private CurrentLotteryNumCommunicater currentLotteryNumCommunicater;
	/** 复式代购购买进度 */
	private ProgressDialog progressdialogNormalbuy;
	/** 复式代购Handler */
	public static Handler handlerNormalBuy;
	/** 标识位,购买成功 */
	private static final int NORMALBUY_SUCCEED = 1001;
	/** 标识位,购买失败 */
	private static final int NORMALBUY_FAIL = 1002;
	/** 标识位,获取余额成功 */
	private static final int GETBALANCE_SUCCEED = 1003;
	/** 标识位,获取余额失败 */
	private static final int GETBALANCE_FAIL = 1004;
	/** 标识（用于随机个数Dialog适配）红球 */
	private static final int REDBALL = 0;
	/** 标识（用于随机个数Dialog适配）蓝球 */
	private static final int BLUEBALL = 1;
	/** 获取期号成功 */
	private static final int GET_EXPECT_LIST_SUCCEED = 10005;
	/** 获取期号失败 */
	private static final int GET_EXPECT_LIST_FAILED = 10006;
	/** 获取上期中奖号码成功 */
	private static final int GET_LOTTERY_NUM_SUCCEED = 10007;
	/** 获取上期中奖号码失败 */
	private static final int GET_LOTTERY_NUM_FAILED = 10008;
	/** 判断是否中奖后停止追号 */
	private boolean isStopZhuihao = false;
	/** 判断是否获取到余额 */
	private boolean isGetBalance;
	/** 购买成功Dialog */
	private Dialog dialogBuySucceed;
	/** 余额不足Dialog */
	private Dialog dialogBalanceNotEnough;
	private View.OnClickListener moneyNotEnoughListener;
	/** 最新开奖号码信息 */
	private CurrentLotteryNumInfo lotteryNumInfo;
	/** 标志位 当选择随机个数Dialog正在显示的时候不支持晃动选号 */
	private boolean isRandomDialogNotShow = true;
	public static final int DO_REFRESH = 10009;
	/*******************************************************/

	/************************* 晃动相关 **********************/
	private SensorManager sensorMgr;
	private long lastUpdate = -1;
	private float x, y, z;
	private float last_x, last_y, last_z;
	private static final int SHAKE_THRESHOLD = 800;

	/*******************************************************/

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		chooseView = this.getLayoutInflater().inflate(R.layout.shuangseqiu_choose_act, null);
		lotteryListView = this.getLayoutInflater().inflate(R.layout.shuangseqiu_choose_act_list, null);
		pageTag = 1;
		initDate();
		initHandler();
		initChooseViewUI();
		initLotteryListViewUI();
		determineSetContentView();
	}

	/** 判定显示选球界面还是列表界面,当菜单中有内容时直接显示列表,没有则进入选球界面 */
	private void determineSetContentView() {

		if (ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().size() == 0) {
			setContentView(chooseView);
			btnCancel.setVisibility(View.GONE);
			isChooseView = true;
			Message msg = ShuangseqiuAgp.handlerShuangseqiu.obtainMessage(ShuangseqiuAgp.IN_CHOOSE_VIEW, null);
			ShuangseqiuAgp.handlerShuangseqiu.sendMessage(msg);
		} else {
			updataListView();
			isChooseView = false;
			Message msg = ShuangseqiuAgp.handlerShuangseqiu.obtainMessage(ShuangseqiuAgp.IN_LIST_VIEW, null);
			ShuangseqiuAgp.handlerShuangseqiu.sendMessage(msg);
			setContentView(lotteryListView);
		}
	}

	private void initLotteryListViewUI() {

		btnListClean = (Button) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_btn_cleanlist);
		btnListClean.setOnClickListener(this);

		btnListCancel = (Button) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_btn_cancel);
		btnListCancel.setOnClickListener(this);

		btnListAdd = (Button) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_btn_add);
		btnListAdd.setOnClickListener(this);

		btnListHemai = (Button) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_btn_hemai);
		btnListHemai.setOnClickListener(this);

		btnListSubmit = (Button) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_btn_submit);
		btnListSubmit.setOnClickListener(this);

		tvListBetCount = (TextView) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_tv_zhushu);

		tvListMoney = (TextView) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_tv_qianshu);

		linearListSpace = (LinearLayout) lotteryListView.findViewById(R.id.shuangseqiuchooseactlist_linear_listSpace);

		listenerListItem = new OnClickListener() {

			@Override
			public void onClick(View v) {

				listTagShow = Integer.parseInt(String.valueOf(v.getTag()));
				setChooseview();
			}
		};
		btnUserAgreement = (LinearLayout) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_btn_xieyi);
		btnUserAgreement.setOnClickListener(this);
		llSetBeitouZhuihao = (LinearLayout) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_btn_setbeitou);
		llSetBeitouZhuihao.setOnClickListener(this);
		tvListBeiShu = (TextView) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_tv_beishu);
		tvListZhuiHao = (TextView) lotteryListView.findViewById(R.id.shuangseqiuchooselistact_tv_qishu);
		progressdialogNormalbuy = ViewerUtil.showProgressDialog(this, Language.POPLOTTERYTIP_BUYING);
	}

	private void initChooseViewUI() {

		tvBetNum = (TextView) chooseView.findViewById(R.id.shuangseqiuchooseact_tv_betNum);
		tvMoney = (TextView) chooseView.findViewById(R.id.shuangseqiuchooseact_tv_money);
		ivRedRandomNum = (ImageView) chooseView.findViewById(R.id.shuangseqiuchooseact_iv_redjiantou);
		ivRedRandomNum.setImageResource(R.drawable.icon_default_random_red_arrows_19x11);

		ivBlueRandomNum = (ImageView) chooseView.findViewById(R.id.shuangseqiuchooseact_iv_bluejiantou);
		ivBlueRandomNum.setImageResource(R.drawable.icon_default_random_blue_arrows_19x11);

		ballMenuBuilderRed = new BallMenuBuilder(this, 33, 20, 0, tvBetNum, tvMoney, Config.SHUANGSEQIU);
		ballMenuBuilderBlue = new BallMenuBuilder(this, 16, 17, 1, tvBetNum, tvMoney, Config.SHUANGSEQIU);

		linearBallMenuBlue = (LinearLayout) chooseView.findViewById(R.id.shuangseqiuchooseact_Linear_ballMenuBlue);
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(linearBallMenuBlue.getLayoutParams());
		lp.gravity = Gravity.CENTER_VERTICAL;
		lp.height = LinearLayout.LayoutParams.FILL_PARENT;
		lp.width = LinearLayout.LayoutParams.FILL_PARENT;
		linearBallMenuBlue.addView(ballMenuBuilderBlue.setKeyBoad(), lp);

		linearBallMenuRed = (LinearLayout) chooseView.findViewById(R.id.shuangseqiuchooseact_Linear_ballMenuRed);
		linearBallMenuRed.addView(ballMenuBuilderRed.setKeyBoad());

		btnCancel = (Button) chooseView.findViewById(R.id.shuangseqiuchooseact_btn_cancel);
		btnCancel.setOnClickListener(this);

		btnClean = (Button) chooseView.findViewById(R.id.shuangseqiuchooseact_btn_clean);
		btnClean.setOnClickListener(this);

		btnRandom = (Button) chooseView.findViewById(R.id.shuangseqiuchooseact_btn_random);
		btnRandom.setOnClickListener(this);

		btnSubmit = (Button) chooseView.findViewById(R.id.shuangseqiuchooseact_btn_submit);
		btnSubmit.setOnClickListener(this);

		btnRedRandom = (Button) chooseView.findViewById(R.id.shuangseqiuchooseact_btn_redRandom);
		btnRedRandom.setOnClickListener(this);

		btnBlueRandom = (Button) chooseView.findViewById(R.id.shuangseqiuchooseact_btn_blueRandom);
		btnBlueRandom.setOnClickListener(this);

		btnLastLotteryNum = (Button) chooseView.findViewById(R.id.shuangseqiuchooseact_btn_lottery_num);
		btnLastLotteryNum.setOnClickListener(this);

		btnBlueRandomNum = (LinearLayout) chooseView.findViewById(R.id.shuangseqiuchooseact_btn_blueRandomnum);
		btnBlueRandomNum.setOnClickListener(this);

		tvBlueRandomNum = (TextView) chooseView.findViewById(R.id.shuangseqiuchooseact_tv_blueRandomnum);

		btnRedRandomNum = (LinearLayout) chooseView.findViewById(R.id.shuangseqiuchooseact_btn_redRandomnum);
		btnRedRandomNum.setOnClickListener(this);

		tvRedRandomNum = (TextView) chooseView.findViewById(R.id.shuangseqiuchooseact_tv_redRandomnum);

		llLastLotteryNum = (LinearLayout) chooseView.findViewById(R.id.shuangseqiuchooseact_ll_lottery_num);
		llLastLotteryNum.setOnClickListener(this);

		llLastLotteryNumProgress = (LinearLayout) chooseView.findViewById(R.id.shuangseqiuchooseact_ll_lottery_num_progress);

		llLastLotteryNumShibai = (LinearLayout) chooseView.findViewById(R.id.shuangseqiuchooseact_ll_lottery_num_shibai);
		llLastLotteryNumShibai.setOnClickListener(this);

		tvLastLotteryNumRed = (TextView) chooseView.findViewById(R.id.shuangseqiuchooseact_tv_lottery_numred);
		tvLastLotteryNumBlue = (TextView) chooseView.findViewById(R.id.shuangseqiuchooseact_tv_lottery_numblue);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		// 取消
		case R.id.shuangseqiuchooseact_btn_cancel:
			isChooseView = false;
			listTagShow = -1;

			/** title change 2011-7-27 city */
			Message msg = ShuangseqiuAgp.handlerShuangseqiu.obtainMessage(ShuangseqiuAgp.IN_LIST_VIEW, null);
			ShuangseqiuAgp.handlerShuangseqiu.sendMessage(msg);

			this.setContentView(lotteryListView);
			ballMenuBuilderBlue.cleanKeyBoad();
			ballMenuBuilderRed.cleanKeyBoad();
			break;
		// 清除
		case R.id.shuangseqiuchooseact_btn_clean:
			ballMenuBuilderBlue.cleanKeyBoad();
			ballMenuBuilderRed.cleanKeyBoad();
			break;

		// 机选一注
		case R.id.shuangseqiuchooseact_btn_random:
			isChooseView = false;
			singleRandom();
			break;

		// 提交
		case R.id.shuangseqiuchooseact_btn_submit:
			int money = Integer.valueOf(tvMoney.getText().toString().replace(Config.ONESPACE, Config.NULLMARK));
			if (money > Config.MAXIMUM_BET_SHUANGSEQIU) {
				ViewerUtil.showTipDialog(ShuangseqiuChooseAct.this, getResources().getString(R.string.maximum_bet_ssq), false);
			} else {
				setListView();
			}
			break;

		// 机选红球
		case R.id.shuangseqiuchooseact_btn_redRandom:
			isChooseView = false;
			redBallRandom();
			break;

		// 机选篮球
		case R.id.shuangseqiuchooseact_btn_blueRandom:
			isChooseView = false;
			blueBallRandom();
			break;

		// 继续选号
		case R.id.shuangseqiuchooselistact_btn_cancel:
			setChooseview();
			break;

		// 清空列表
		case R.id.shuangseqiuchooselistact_btn_cleanlist:
			ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().clear();
			beishuEnd = Config.NUM1;
			zhuihaoEnd = Config.NUM1;
			tvListBeiShu.setText(beishuEnd);
			tvListZhuiHao.setText(zhuihaoEnd);
			updataListViewWithMsg();
			break;

		// 添加随机投注
		case R.id.shuangseqiuchooselistact_btn_add:
			randomLotQuickAdd();
			break;

		// 购买
		case R.id.shuangseqiuchooselistact_btn_submit:
			showShuangseqiuNormalBuy();
			break;

		// 发起合买
		case R.id.shuangseqiuchooselistact_btn_hemai:
			showShuangseqiuHemai();
			break;

		// 删除
		case R.id.buylistlinearitem_btn_delete:
			View viewListItem = (View) v.getParent().getParent().getParent();
			RelativeLayout linearItem = (RelativeLayout) viewListItem.findViewById(R.id.buylistlinearitem_linear_item);
			int tag = (Integer) linearItem.getTag();
			EDebug.o(ShuangseqiuChooseAct.this, "buylistlinearitem_btn_delete is click & the tag is " + String.valueOf(viewListItem.getTag()));
			deleteListItem(viewListItem, tag);
			break;

		// 机选蓝球个数
		case R.id.shuangseqiuchooseact_btn_blueRandomnum:
			randomNumTag = RANDOMBLUEBALLTAG;
			EDebug.o("blueRandom", "blueRandom====================================");
			showRandomNumDialogAdapter = new ShowRandomNumDialogAdapter(ShuangseqiuChooseAct.this, arrBlueBallNum, BLUEBALL);
			if (dialogBlue == null) {
				dialogBlue = ViewerUtil.showRandomNumDialog(ShuangseqiuChooseAct.this, showRandomNumDialogAdapter);
			}
			ivBlueRandomNum.setImageResource(R.drawable.icon_up_random_blue_arrows_19x11);
			// 监听Dialog消失事件
			dialogBlue.setOnDismissListener(new OnDismissListener() {
				@Override
				public void onDismiss(DialogInterface dialog) {
					if (isClicked) {// 是点击Dialog中的按钮导致Dialog消失的则显示个数并执行机选
						tvBlueRandomNum.setText(Integer.toString(randomBlueBallNum) + Language.MSG_GE);
						blueBallRandom();
					} else {// 按返回键导致Dialog消失的则只显示个数不执行机选
						if (randomBlueBallNum == 0) {
							tvBlueRandomNum.setText(Config.NUM1 + Language.MSG_GE);
						}
					}
					ivBlueRandomNum.setImageResource(R.drawable.icon_default_random_blue_arrows_19x11);
					isClicked = false;
					isRandomDialogNotShow = true;
				}
			});
			// 设置Dialog显示位置
			int[] locationBlue = new int[2];
			linearBallMenuBlue.getLocationOnScreen(locationBlue);
			int yBlue = locationBlue[1];
			int topHeightBlue = getTopHeight();
			EDebug.o("yRed:" + yBlue + "topHeight" + topHeightBlue);
			yBlue = yBlue - topHeightBlue;
			EDebug.o("yRed:" + yBlue);
			Window blueDialogWindow = dialogBlue.getWindow();
			blueDialogWindow.setGravity(Gravity.RIGHT | Gravity.TOP);
			WindowManager.LayoutParams bluelp = blueDialogWindow.getAttributes();
			bluelp.x = 8;
			bluelp.y = yBlue;
			dialogBlue.onWindowAttributesChanged(bluelp);
			dialogBlue.show();
			isRandomDialogNotShow = false;
			break;
		// 机选红球个数
		case R.id.shuangseqiuchooseact_btn_redRandomnum:
			randomNumTag = RANDOMREDBALLTAG;
			EDebug.o("redRandom", "redRandom====================================");
			showRandomNumDialogAdapter = new ShowRandomNumDialogAdapter(ShuangseqiuChooseAct.this, arrRedBallNum, REDBALL);
			if (dialogRed == null) {
				dialogRed = ViewerUtil.showRandomNumDialog(ShuangseqiuChooseAct.this, showRandomNumDialogAdapter);
			}
			ivRedRandomNum.setImageResource(R.drawable.icon_up_random_red_arrows_19x11);
			// 监听Dialog消失事件
			dialogRed.setOnDismissListener(new OnDismissListener() {
				@Override
				public void onDismiss(DialogInterface dialog) {
					if (isClicked) {// 是点击Dialog中的按钮导致Dialog消失的则显示个数并执行机选
						tvRedRandomNum.setText(Integer.toString(randomRedBallNum) + Language.MSG_GE);
						redBallRandom();
					} else {// 按返回键导致Dialog消失的则只显示个数不执行机选
						if (randomRedBallNum == 0) {
							tvRedRandomNum.setText(Config.NUM6 + Language.MSG_GE);
						}
					}
					ivRedRandomNum.setImageResource(R.drawable.icon_default_random_red_arrows_19x11);
					isClicked = false;
					isRandomDialogNotShow = true;
				}
			});
			// 设置Dialog显示位置
			int[] locationRed = new int[2];
			linearBallMenuRed.getLocationOnScreen(locationRed);
			int yRed = locationRed[1];
			int topHeightRed = getTopHeight();
			EDebug.o("yRed:" + yRed + "topHeight" + topHeightRed);
			yRed = yRed - topHeightRed;
			EDebug.o("yRed:" + yRed);
			Window redDialogWindow = dialogRed.getWindow();
			redDialogWindow.setGravity(Gravity.RIGHT | Gravity.TOP);
			WindowManager.LayoutParams redlp = redDialogWindow.getAttributes();
			redlp.x = 8;
			redlp.y = yRed;
			dialogRed.onWindowAttributesChanged(redlp);
			dialogRed.show();
			isRandomDialogNotShow = false;
			break;
		// 上期中奖号码
		case R.id.shuangseqiuchooseact_btn_lottery_num:
			btnLastLotteryNum.setVisibility(View.GONE);
			// 如果红色号码和蓝色号码都不为空，直接显示，如果为空，去服务器获取
			if (redcode != null && !redcode.equals(Config.NULLMARK) && bluecode != null && !bluecode.equals(Config.NULLMARK)) {
				llLastLotteryNum.setVisibility(View.VISIBLE);
				tvLastLotteryNumRed.setText(redcode);
				tvLastLotteryNumBlue.setText(bluecode);
			} else {
				llLastLotteryNumProgress.setVisibility(View.VISIBLE);
				threadGetCurrentLotteryNum(Config.SHUANGSEQIU);
			}

			break;
		// 显示上期中奖号码的LinearLayout
		case R.id.shuangseqiuchooseact_ll_lottery_num:
			btnLastLotteryNum.setVisibility(View.VISIBLE);
			llLastLotteryNum.setVisibility(View.GONE);
			break;
		// 显示获取上期中奖号码失败的LinearLayout
		case R.id.shuangseqiuchooseact_ll_lottery_num_shibai:
			btnLastLotteryNum.setVisibility(View.VISIBLE);
			llLastLotteryNumShibai.setVisibility(View.GONE);
			break;
		// 用户代购协议
		case R.id.shuangseqiuchooselistact_btn_xieyi:
			Intent intent = new Intent();
			intent.putExtra(Key.KEY_URL, Config.USER_DAIGOUXIEYI_WEBVIEW_URL);
			intent.putExtra(Key.KEY_TITLE, "用户合同代购协议");
			intent.setClass(this, WebViewActivity.class);
			this.startActivity(intent);
			break;
		// 设置倍投追号
		case R.id.shuangseqiuchooselistact_btn_setbeitou:
			showBeitouZhuihaoDialog();
			break;
		// 提交倍投追号
		case R.id.dialog_beitou_zhuihao_btn_submit:
			beishuEnd = beishuCurrent;
			zhuihaoEnd = zhuihaoCurrent;
			int moneyEnd = Integer.parseInt(beishuEnd) * moneyAll;
			beiTouZhuihaoDialog.dismiss();
			tvListBeiShu.setText(beishuEnd);
			tvListZhuiHao.setText(zhuihaoEnd);
			tvListMoney.setText(Integer.toString(moneyEnd));
			break;
		// 取消倍投追号
		case R.id.dialog_beitou_zhuihao_btn_cancle:
			beiTouZhuihaoDialog.dismiss();
			break;
		// 购买提交
		case R.id.dialogquit_btn_submit:
			submitOrderDialog.dismiss();
			progressdialogNormalbuy.show();
			String termNum = ShuangseqiuInfo.getShuangseqiuInfo().getTermNum();
			threadGetExpectList(termNum, zhuihaoEnd);
			break;
		// 取消
		case R.id.dialogquit_btn_cancel:
			submitOrderDialog.dismiss();
			break;

		default:
			break;
		}

	}

	private void deleteListItem(View view, int tag) {
		linearListSpace.removeView(view);
		ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().remove(tag);
		updataListViewWithMsg();
	}

	/**
	 * @Title: showShuangseqiuNormalBuy
	 * @Description: 双色球复式代购
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void showShuangseqiuNormalBuy() {
		pageTag = 1;

		if (ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().size() == 0) {// 至少选择一注
			ViewerUtil.showTipDialog(ShuangseqiuChooseAct.this, Language.STR_ZUISHAOXUANZEYIZHUHAOMA, false);
		} else if (UserInfo.getUserInfo().getUserSession().length() < 3) {// 判断是否需要登录
			Intent intentToLogin = new Intent();
			intentToLogin.setClass(ShuangseqiuChooseAct.this, LoginAct.class);
			startActivity(intentToLogin);
		} else if (!isGetBalance) {// 判断是否获取余额中
			ViewerUtil.showTipDialog(ShuangseqiuChooseAct.this, Language.MSG_WAIT_GET_YUE, false);
		} else if (Double.parseDouble(UserInfo.getUserInfo().getUserBalance()) == 0) {// 余额不足
			showZeroMoneyDialog(1);
		} else {
			LoginTimeControl test = new LoginTimeControl();
			if (test.isNeedInputPwd()) {// 判断是否需要输入密码
				test.showInputPasswordDialog(ShuangseqiuChooseAct.this);
			} else {// 显示提交订单Dialog
				if (submitOrderDialog == null) {
					showSubmitOrderDialog(Language.MSG_ASK_SUBMIT_ORDER, Language.MSG_SUBMIT);
				}
				submitOrderDialog.show();
			}
		}

	}

	private void singleRandom() {

		OnClickListener randomSingleListener = new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				isChooseView = false;
				ShuangseqiuChooseAct.this.setContentView(lotteryListView);
				int randomCount = ViewerUtil.getRandomCount();
				for (int i = 0; i < randomCount; i++) {
					addSingleRandomToList();
				}
				listTagShow = -1;
				ViewerUtil.dismissRandomDialog();
				ViewerUtil.isInChooseView = true;
				updataListViewWithMsg();
				randomZhuShu = randomCount;
				EDebug.o("randomzhushu------------", "机选注数" + randomZhuShu);
			}
		};
		EDebug.o("randomzhushu------------", "机选注数" + randomZhuShu);
		ViewerUtil.showRandomDialog(ShuangseqiuChooseAct.this, Language.MSG_SELECT_SUIJI_ZHUSHU, 1, 10, 10, randomZhuShu, randomSingleListener);

	}

	private void showShuangseqiuHemai() {

		EDebug.o(ShuangseqiuChooseAct.this, "合买页面,走你");
		pageTag = 2;
		if (ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().size() == 0) {
			ViewerUtil.showTipDialog(ShuangseqiuChooseAct.this, Language.STR_ZUISHAOXUANZEYIZHUHAOMA, false);
		} else if (UserInfo.getUserInfo().getUserSession().length() < 3) {
			Intent intentToLogin = new Intent();
			intentToLogin.setClass(ShuangseqiuChooseAct.this, LoginAct.class);
			startActivity(intentToLogin);
		}
		// else if (Double.parseDouble(UserInfo.getUserInfo().getUserBalance())
		// == 0) {
		// showZeroMoneyDialog(2);
		// }
		else {
			// 合买页面,走你
			EDebug.o(ShuangseqiuChooseAct.this, "合买页面,走你");
			Intent intentToHemai = new Intent();
			intentToHemai.setClass(ShuangseqiuChooseAct.this, ShuangseqiuChooseHemaiAct.class);
			startActivity(intentToHemai);
		}

	}

	/**
	 * @Title: blueBallRandom
	 * @Description: 随机蓝球处理
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void blueBallRandom() {
		isChooseView = false;
		if (randomBlueBallNum == 0) {
			ballMenuBuilderBlue.setKeyBoadRandom(LotteryUtils.randomNum(1, 16));
		} else {
			ballMenuBuilderBlue.setKeyBoadRandom(LotteryUtils.randomNum(randomBlueBallNum, 16));
			isChooseView = true;
		}
	}

	/**
	 * @Title: redBallRandom
	 * @Description: 随机红球处理
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void redBallRandom() {
		isChooseView = false;
		if (randomRedBallNum == 0) {
			ballMenuBuilderRed.setKeyBoadRandom(LotteryUtils.randomNum(6, 33));
		} else {
			ballMenuBuilderRed.setKeyBoadRandom(LotteryUtils.randomNum(randomRedBallNum, 33));
			isChooseView = true;
		}

	}

	// 选球界面确认选号
	private void setListView() {

		ViewerUtil.isShowRegist = false;
		if (ShuangseqiuInfo.getShuangseqiuInfo().getBetCount() < 1) {
			ViewerUtil.showTipDialog(this, Language.MSG_ZUISHAOXUANZELIUYI, false);
		} else if (listTagShow == -1) {
			HashMap<String, Object> lotteryListItem = new HashMap<String, Object>();
			lotteryListItem.put(Key.KEY_BLUE, ListToString(ballMenuBuilderBlue.getListResult()));
			lotteryListItem.put(Key.KEY_RED, ListToString(ballMenuBuilderRed.getListResult()));
			lotteryListItem.put(Key.KEY_BET_COUNT, ShuangseqiuInfo.getShuangseqiuInfo().getBetCount());
			ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().add(lotteryListItem);
			this.setContentView(lotteryListView);
			updataListViewWithMsg();
		} else {
			HashMap<String, Object> lotteryListItem = new HashMap<String, Object>();
			lotteryListItem.put(Key.KEY_BLUE, ListToString(ballMenuBuilderBlue.getListResult()));
			lotteryListItem.put(Key.KEY_RED, ListToString(ballMenuBuilderRed.getListResult()));
			lotteryListItem.put(Key.KEY_BET_COUNT, ShuangseqiuInfo.getShuangseqiuInfo().getBetCount());
			ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().set(listTagShow, lotteryListItem);
			this.setContentView(lotteryListView);
			updataListViewWithMsg();
			listTagShow = -1;
		}
	}

	private void updataListViewWithMsg() {
		/** title change 2011-7-27 city */
		Message msg = ShuangseqiuAgp.handlerShuangseqiu.obtainMessage(ShuangseqiuAgp.IN_LIST_VIEW, null);
		ShuangseqiuAgp.handlerShuangseqiu.sendMessage(msg);
		updataListView();
	}

	private void updataListView() {

		linearListSpace.removeAllViews();

		isChooseView = false;

		LayoutParams param = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		for (int i = ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().size() - 1; i > 0 - 1; i--) {
			View viewListItem = ShuangseqiuChooseAct.this.getLayoutInflater().inflate(R.layout.buylist_linear_item, null);
			int redLength = ((String) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(i).get(Key.KEY_RED)).length();
			int blueLength = ((String) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(i).get(Key.KEY_BLUE)).length();
			EDebug.o(ShuangseqiuChooseAct.this, "the tag is " + String.valueOf(viewListItem.getTag()));

			TextView tvItemRed = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_red);
			tvItemRed.setText(strLengthOption((String) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(i).get(Key.KEY_RED), 17));

			TextView tvItemBlue = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_blue);
			tvItemBlue.setText(strLengthOption((String) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(i).get(Key.KEY_BLUE), 10));
			TextView tvValue = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_value);
			// 注掉的原因是解决投注注数和金额显示不全的问题
			// tvValue.setText(strLengthOption(stringListItemValue(i), 7));
			tvValue.setText(stringListItemValue(i));
			TextView tvItemStyle = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_touzhustyle);
			if (redLength == 17 && blueLength == 2) {
				tvItemStyle.setText(Language.MSG_DANSHITOUZHU);
			} else {
				tvItemStyle.setText(Language.MSG_FUSHITOUZHU);
			}

			RelativeLayout lotteryData = (RelativeLayout) viewListItem.findViewById(R.id.buylistlinearitem_linear_item);
			lotteryData.setTag(i);
			lotteryData.setOnClickListener(listenerListItem);

			Button btnItemDelete = (Button) viewListItem.findViewById(R.id.buylistlinearitem_btn_delete);
			btnItemDelete.setOnClickListener(ShuangseqiuChooseAct.this);

			linearListSpace.addView(viewListItem, param);
		}
		ballMenuBuilderBlue.cleanKeyBoad();
		ballMenuBuilderRed.cleanKeyBoad();

		betCountAll = 0;
		for (int i = 0; i < ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().size(); i++) {
			betCountAll += (Integer) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(i).get(Key.KEY_BET_COUNT);
		}
		moneyAll = betCountAll * 2;
		int money = moneyAll * Integer.parseInt(beishuEnd);
		tvListBetCount.setText(Integer.toString(betCountAll));
		tvListMoney.setText(Integer.toString(money));
	}

	// 返回选球界面
	private void setChooseview() {

		/** title change 2011-7-27 city */
		Message msg = ShuangseqiuAgp.handlerShuangseqiu.obtainMessage(ShuangseqiuAgp.IN_CHOOSE_VIEW, null);
		ShuangseqiuAgp.handlerShuangseqiu.sendMessage(msg);

		isChooseView = true;
		setContentView(chooseView);
		if (ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().size() == 0) {
			btnCancel.setVisibility(View.GONE);
		} else if (listTagShow != -1) {
			btnCancel.setVisibility(View.VISIBLE);
			ballMenuBuilderRed.setKeyBoadRandom(StringToList((String) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(listTagShow).get(Key.KEY_RED)));
			ballMenuBuilderBlue.setKeyBoadRandom(StringToList((String) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(listTagShow).get(Key.KEY_BLUE)));
			EDebug.o(this, "listTagShow 走着");
		} else {
			btnCancel.setVisibility(View.VISIBLE);
		}
	}

	private ArrayList<Integer> StringToList(String str) {
		ArrayList<Integer> integers = new ArrayList<Integer>();
		String[] strs = str.split(Config.ONESPACE);
		for (int i = 0; i < strs.length; i++) {
			integers.add(Integer.parseInt(strs[i]));
		}
		return integers;
	}

	// 快速添加一注随机选号
	private void randomLotQuickAdd() {

		addSingleRandomToList();

		LayoutParams param = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
		int intTag = ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().size() - 1;
		int redLength = ((String) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(intTag).get(Key.KEY_RED)).length();
		int blueLength = ((String) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(intTag).get(Key.KEY_BLUE)).length();
		View viewListItem = ShuangseqiuChooseAct.this.getLayoutInflater().inflate(R.layout.buylist_linear_item, null);

		TextView tvItemRed = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_red);
		tvItemRed.setText(strLengthOption((String) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(intTag).get(Key.KEY_RED), 17));

		TextView tvItemBlue = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_blue);
		tvItemBlue.setText(strLengthOption((String) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(intTag).get(Key.KEY_BLUE), 10));
		TextView tvValue = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_value);
		tvValue.setText(strLengthOption(stringListItemValue(intTag), 7));

		Button btnItemDelete = (Button) viewListItem.findViewById(R.id.buylistlinearitem_btn_delete);
		btnItemDelete.setOnClickListener(ShuangseqiuChooseAct.this);

		TextView tvItemStyle = (TextView) viewListItem.findViewById(R.id.buylistlinearitem_tv_touzhustyle);
		if (redLength == 17 && blueLength == 2) {
			tvItemStyle.setText(Language.MSG_DANSHITOUZHU);
		} else {
			tvItemStyle.setText(Language.MSG_FUSHITOUZHU);
		}
		RelativeLayout lotteryData = (RelativeLayout) viewListItem.findViewById(R.id.buylistlinearitem_linear_item);
		lotteryData.setTag(intTag);
		lotteryData.setOnClickListener(listenerListItem);

		viewListItem.setAnimation(AnimationUtils.loadAnimation(ShuangseqiuChooseAct.this, R.anim.push_left_in));

		linearListSpace.addView(viewListItem, 0, param);

		betCountAll++;
		moneyAll = betCountAll * 2;
		int money = moneyAll * Integer.parseInt(beishuEnd);
		tvListBetCount.setText(Integer.toString(betCountAll));
		tvListMoney.setText(Integer.toString(money));
	}

	private void addSingleRandomToList() {
		HashMap<String, Object> lotteryListItem = new HashMap<String, Object>();
		lotteryListItem.put(Key.KEY_BLUE, ListIntToString(LotteryUtils.randomNum(1, 16)));
		lotteryListItem.put(Key.KEY_RED, ListIntToString(LotteryUtils.randomNum(6, 33)));
		lotteryListItem.put(Key.KEY_BET_COUNT, 1);
		if (listTagShow == -1) {
			ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().add(lotteryListItem);
		} else {
			ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().add(listTagShow, lotteryListItem);
		}
	}

	// 工具类,待合并
	private String ListToString(List<String> str) {
		StringBuffer sb = new StringBuffer();
		if (str.get(0).length() == 1) {
			sb.append(Config.NUM0).append(str.get(0));
		} else {
			sb.append(str.get(0));
		}
		for (int i = 1; i < str.size(); i++) {
			sb.append(Config.ONESPACE);
			if (str.get(i).length() == 1) {
				sb.append(Config.NUM0).append(str.get(i));
			} else {
				sb.append(str.get(i));
			}
		}
		String result = sb.toString();
		return result;
	}

	private String ListIntToString(List<Integer> list) {
		StringBuffer sb = new StringBuffer();
		if (list.get(0) < 10) {
			sb.append(Config.NUM0).append(Integer.toString(list.get(0)));
		} else {
			sb.append(Integer.toString(list.get(0)));
		}
		for (int i = 1; i < list.size(); i++) {
			sb.append(Config.ONESPACE);
			if (list.get(i) < 10) {
				sb.append(Config.NUM0).append(Integer.toString(list.get(i)));
			} else {
				sb.append(Integer.toString(list.get(i)));
			}
		}

		String result = sb.toString();
		return result;
	}

	private String stringListItemValue(int position) {
		StringBuffer sb = new StringBuffer();
		int bet_count = (Integer) ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().get(position).get(Key.KEY_BET_COUNT);
		int money = bet_count * 2;
		sb.append(Integer.toString(bet_count)).append(Language.POPLOTTERYTIP_ZHU).append(Integer.toString(money)).append(Language.POPLOTTERYTIP_YUAN);

		String result = sb.toString();
		return result;
	}

	private String strLengthOption(String str, int max) {
		EDebug.o(this, str + "==>" + str.length() + "==>" + max);
		if (str.length() < max + 1) {
			return str;
		} else {
			StringBuffer sb = new StringBuffer();
			sb.append(str.substring(0, max - 2)).append(Config.ELLIPSIS);
			String result = sb.toString();
			return result;
		}
	}

	// 将menu键点击事件返回给父activity处理
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
			Activity parent = getParent();
			if (parent != null) {
				parent.onKeyDown(keyCode, event);
				return true;
			}
		}

		if (keyCode == KeyEvent.KEYCODE_BACK) {
			getParent().finish();
			if (UserInfo.getUserInfo().isRebuy()) {
				ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().clear();
				UserInfo.getUserInfo().setRebuy(false);
			}
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public boolean onTrackballEvent(MotionEvent event) {

		Activity parent = getParent();
		if (parent != null) {
			parent.onTrackballEvent(event);
			return true;
		}
		return false;
	}

	@Override
	protected void onResume() {
		initShake();
		super.onResume();
		determineSetContentView();
		if (showType == 1) {
			getParent().finish();
		} else if (showType == 2) {
			determineSetContentView();
			// setChooseview();
		}

		if (UserInfo.getUserInfo().isBuyingRecharge() && UserInfo.getUserInfo().isRechargeSucceed()) {
			getParent().finish();
			UserInfo.getUserInfo().setBuyingRecharge(false);
			UserInfo.getUserInfo().setRechargeSucceed(false);
		} else if ((!UserInfo.getUserInfo().isBuyingRecharge()) && UserInfo.getUserInfo().isRechargeSucceed()) {
			UserInfo.getUserInfo().setRechargeSucceed(false);

			if (pageTag == 2) {
				Intent intentGoon = new Intent();
				intentGoon.setClass(ShuangseqiuChooseAct.this, ShuangseqiuChooseHemaiAct.class);
				startActivity(intentGoon);
			}

		} else {
			UserInfo.getUserInfo().setBuyingRecharge(false);
			EDebug.o(ShuangseqiuChooseAct.this, "no recharge normal in ");
		}

		if (RegistAct.isRegistSucceed || OptionAct.isLoginSucceed) {
			if (Double.parseDouble(UserInfo.getUserInfo().getUserBalance()) - moneyAll < 0) {
				showZeroMoneyDialog(pageTag);
			}
			RegistAct.isRegistSucceed = false;
			OptionAct.isLoginSucceed = false;
		}

		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());
		if (UserInfo.getUserInfo().isBuyingRecharge()) {
			ShuangseqiuChooseAct.this.finish();
			UserInfo.getUserInfo().setBuyingRecharge(false);
			ShuangseqiuChooseAct.showType = 1;
		}
		isGetBalance = false;
		threadGetUserBalance();
	}

	@Override
	protected void onPause() {
		super.onPause();
		if (sensorMgr != null) {
			sensorMgr.unregisterListener(this, SensorManager.SENSOR_ACCELEROMETER);
			sensorMgr = null;
		}
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());

	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onAccuracyChanged(int sensor, int accuracy) {

	}

	@Override
	public void onSensorChanged(int sensor, float[] values) {

		if (sensor == SensorManager.SENSOR_ACCELEROMETER) {
			long curTime = System.currentTimeMillis();
			if ((curTime - lastUpdate) > 100) {
				long diffTime = (curTime - lastUpdate);
				lastUpdate = curTime;

				x = values[SensorManager.DATA_X];
				y = values[SensorManager.DATA_Y];
				z = values[SensorManager.DATA_Z];

				float speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;

				if (speed > SHAKE_THRESHOLD) {
					if (isChooseView && isRandomDialogNotShow) {
						ballMenuBuilderRed.setKeyBoadRandom(LotteryUtils.randomNum(6, 33));
						ballMenuBuilderBlue.setKeyBoadRandom(LotteryUtils.randomNum(1, 16));
						new Vibrate(this).playVibrate(-1);
					}
				}
				last_x = x;
				last_y = y;
				last_z = z;
			}
		}
	}

	private void initShake() {
		sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE);
		boolean accelSupported = sensorMgr.registerListener(this, SensorManager.SENSOR_ACCELEROMETER, SensorManager.SENSOR_DELAY_GAME);

		if (!accelSupported) {
			// on accelerometer on this device
			sensorMgr.unregisterListener(this, SensorManager.SENSOR_ACCELEROMETER);
		}
	}

	/**
	 * @Title: showZeroMoneyDialog
	 * @Description: 账户余额不足 Dialog
	 * @param: @param pageTag 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void showZeroMoneyDialog(final int pageTag) {
		final Dialog zeroMoneyDialog = new Dialog(ShuangseqiuChooseAct.this, R.style.dialog);
		zeroMoneyDialog.getWindow().setContentView(R.layout.viewerutil_dialog_zeromoney);
		OnClickListener listener = new OnClickListener() {

			@Override
			public void onClick(View v) {

				switch (v.getId()) {
				case R.id.viewerutildialogzeromoney_btn_cancel:
					zeroMoneyDialog.dismiss();

					if (pageTag == 2) {
						Intent intentGoon = new Intent();
						intentGoon.setClass(ShuangseqiuChooseAct.this, ShuangseqiuChooseHemaiAct.class);
						startActivity(intentGoon);
					}
					break;

				case R.id.viewerutildialogzeromoney_btn_recharge:
					zeroMoneyDialog.dismiss();
					Intent intent = new Intent();
					intent.setClass(ShuangseqiuChooseAct.this, RechargeMenuPage.class);
					startActivity(intent);
					UserInfo.getUserInfo().setBuyingRecharge(true);
					break;
				default:
					break;
				}
			}
		};
		Button btnCancel = (Button) zeroMoneyDialog.getWindow().findViewById(R.id.viewerutildialogzeromoney_btn_cancel);
		btnCancel.setText(Language.MSG_CONTINUEBUY);
		btnCancel.setOnClickListener(listener);
		Button btnRecharge = (Button) zeroMoneyDialog.getWindow().findViewById(R.id.viewerutildialogzeromoney_btn_recharge);
		btnRecharge.setOnClickListener(listener);
		((TextView) zeroMoneyDialog.getWindow().findViewById(R.id.viewerutildialogzeromoney_tv_userName)).setText(Language.MSG_YUEBUZUMSG);
		((TextView) zeroMoneyDialog.getWindow().findViewById(R.id.viewerutildialogzeromoney_tv_tipWord)).setVisibility(View.GONE);
		zeroMoneyDialog.show();
	}

	/**
	 * @ClassName: ShowRandomNumDialogAdapter
	 * @Description: 显示选择机选球个数dialog的Adapter
	 * @author: Kael gaojian@500wan.com
	 * @date: 2012-6-21 下午3:11:52
	 * 
	 */
	class ShowRandomNumDialogAdapter extends BaseAdapter {
		private LayoutInflater listInflater;
		private ArrayList<Hashtable<String, Object>> cells;
		private int ballColor;

		public ShowRandomNumDialogAdapter(Context context, ArrayList<Hashtable<String, Object>> cells, int ballColor) {
			this.listInflater = LayoutInflater.from(context);
			this.cells = cells;
			this.ballColor = ballColor;
		}

		@Override
		public int getCount() {
			return cells.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(final int position, View convertView, ViewGroup parent) {
			convertView = (Button) listInflater.inflate(R.layout.viewerutil_dialog_randomnum_cell, null);
			final Button button = (Button) convertView.findViewById(R.id.viewerutil_dialog_randomnum_item);
			button.setText(Integer.toString((Integer) cells.get(position).get(Key.KEY_NUM)));
			button.setHeight(65);
			if (ballColor == REDBALL) {
				switch (position) {
				// 第一行第一个用topleft图做背景
				case 0:
					button.setBackgroundResource(R.drawable.btn_random_redballnum_topleft_style);
					break;
				// 第一行最后一个用topright图做背景
				case 5:
					button.setBackgroundResource(R.drawable.btn_random_redballnum_topright_style);
					break;
				// 最后一行第一个用leftbottom图做背景
				case 12:
					button.setBackgroundResource(R.drawable.btn_random_redballnum_leftbottom_style);
					break;
				// 其他用mid图做背景
				default:
					button.setBackgroundResource(R.drawable.btn_random_redballnum_mid_style);
					break;
				}

			} else {
				switch (position) {
				// 第一行第一个用topleft图做背景
				case 0:
					button.setBackgroundResource(R.drawable.btn_random_blueballnum_topleft_style);
					break;
				// 第一行最后一个用topright图做背景
				case 5:
					button.setBackgroundResource(R.drawable.btn_random_blueballnum_topright_style);
					break;
				// 最后一行第一个用leftbottom图做背景
				case 12:
					button.setBackgroundResource(R.drawable.btn_random_blueballnum_leftbottom_style);
					break;
				// 其他用mid图做背景
				default:
					button.setBackgroundResource(R.drawable.btn_random_blueballnum_mid_style);
					break;
				}

			}
			button.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {

					// 机选蓝球
					if (randomNumTag == RANDOMBLUEBALLTAG) {
						int num = (Integer) cells.get(position).get(Key.KEY_NUM);
						if (randomRedBallNum == 0) {
							randomRedBallNum = 6;
						}

						int count = num * randomRedBallNum * (randomRedBallNum - 1) * (randomRedBallNum - 2) * (randomRedBallNum - 3) * (randomRedBallNum - 4) * (randomRedBallNum - 5);
						int countNum = count / (6 * 5 * 4 * 3 * 2 * 1);
						int moneyNum = countNum * 2;
						EDebug.o("money", "randomRedBallNum" + randomRedBallNum);
						EDebug.o("money", "num" + num);
						EDebug.o("money", "money" + moneyNum);
						if (moneyNum > Config.MAXIMUM_BET_SHUANGSEQIU) {
							Toast.makeText(ShuangseqiuChooseAct.this, Language.MSG_MAXSHIWANYUAN, Toast.LENGTH_SHORT).show();
						} else {
							isClicked = true;
							randomBlueBallNum = (Integer) cells.get(position).get("num");
							dialogBlue.dismiss();
						}

						// 机选红球
					} else if (randomNumTag == RANDOMREDBALLTAG) {
						int num = (Integer) cells.get(position).get(Key.KEY_NUM);
						if (randomBlueBallNum == 0) {
							randomBlueBallNum = 1;
						}
						int count = num * (num - 1) * (num - 2) * (num - 3) * (num - 4) * (num - 5) * randomBlueBallNum;
						int countNum = count / (6 * 5 * 4 * 3 * 2 * 1);
						int moneyNum = countNum * 2;
						EDebug.o("money", "randomBlueBallNum" + randomBlueBallNum);
						EDebug.o("money", "num" + num);
						EDebug.o("money", "money" + moneyNum);
						if (moneyNum > Config.MAXIMUM_BET_SHUANGSEQIU) {
							Toast.makeText(ShuangseqiuChooseAct.this, Language.MSG_MAXSHIWANYUAN, Toast.LENGTH_SHORT).show();
						} else {
							isClicked = true;
							randomRedBallNum = (Integer) cells.get(position).get(Key.KEY_NUM);
							dialogRed.dismiss();
						}

					}

				}
			});
			return convertView;
		}

	}

	/**
	 * @Title: setBlueBallNumArray
	 * @Description: 设定存放机选蓝球个数的ArrayList
	 * @param: @return 设定文件
	 * @return: ArrayList<Hashtable<String,Object>> 返回类型
	 * 
	 */
	private ArrayList<Hashtable<String, Object>> setBlueBallNumArray() {
		ArrayList<Hashtable<String, Object>> blueBallNumArray = new ArrayList<Hashtable<String, Object>>();
		for (int i = 1; i < 17; i++) {
			Hashtable<String, Object> blueBallNumHash = new Hashtable<String, Object>();
			blueBallNumHash.put(Key.KEY_NUM, i);
			blueBallNumArray.add(blueBallNumHash);
		}
		return blueBallNumArray;
	}

	/**
	 * @Title: setRedBallNumArray
	 * @Description: 设定存放机选红球个数的ArrayList
	 * @param: @return 设定文件
	 * @return: ArrayList<Hashtable<String,Object>> 返回类型
	 * 
	 */
	private ArrayList<Hashtable<String, Object>> setRedBallNumArray() {
		ArrayList<Hashtable<String, Object>> redBallNumArray = new ArrayList<Hashtable<String, Object>>();
		for (int i = 6; i < 21; i++) {
			Hashtable<String, Object> redBallNumHash = new Hashtable<String, Object>();
			redBallNumHash.put(Key.KEY_NUM, i);
			redBallNumArray.add(redBallNumHash);
		}
		return redBallNumArray;
	}

	/**
	 * @Title: setWheelContent
	 * @Description: 设置存放追号期数 倍数的ArrayList
	 * @param: @param num
	 * @param: @return 设定文件
	 * @return: ArrayList<String> 返回类型
	 * 
	 */
	private ArrayList<String> setWheelContent(int num) {
		ArrayList<String> array = new ArrayList<String>();
		array.add(Config.NUM0);
		for (int i = 1; i < num + 1; i++) {
			String s = Integer.toString(i);
			array.add(s);
		}
		return array;
	}

	/**
	 * @Title: initDate
	 * @Description: 初始化数据
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void initDate() {
		arrBlueBallNum = new ArrayList<Hashtable<String, Object>>();
		arrRedBallNum = new ArrayList<Hashtable<String, Object>>();
		arrBlueBallNum = setBlueBallNumArray();
		arrRedBallNum = setRedBallNumArray();
		beishuNum = new ArrayList<String>();
		zhuihaoNum = new ArrayList<String>();
		beishuNum = setWheelContent(50);
		zhuihaoNum = setWheelContent(30);

	}

	/**
	 * @Title: showBeitouZhuihaoDialog
	 * @Description: 显示设置倍投 追号的Dialog
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void showBeitouZhuihaoDialog() {

		if (beiTouZhuihaoDialog == null) {
			beiTouZhuihaoDialog = new Dialog(ShuangseqiuChooseAct.this, R.style.dialog);
			beiTouZhuihaoDialog.getWindow().setContentView(R.layout.dialog_beitou_zhuihao_setting);

			btnDialogFinish = (Button) beiTouZhuihaoDialog.findViewById(R.id.dialog_beitou_zhuihao_btn_submit);
			btnDialogFinish.setOnClickListener(this);

			btnDialogCancel = (Button) beiTouZhuihaoDialog.findViewById(R.id.dialog_beitou_zhuihao_btn_cancle);
			btnDialogCancel.setOnClickListener(this);

			cbDialogStop = (CheckBox) beiTouZhuihaoDialog.findViewById(R.id.dialog_cb_stop);
			cbDialogStop.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
					if (isChecked) {
						isStopZhuihao = true;
					} else {
						isStopZhuihao = false;
					}

				}
			});

			beishuWheel = (WheelView) beiTouZhuihaoDialog.findViewById(R.id.dialog_beitou_choose_wheel);
			beishuWheel.setAdapter(new NumericWheelAdapter(beishuNum));
			beishuWheel.setCurrentItem(Integer.parseInt(beishuEnd) - 1);
			beishuWheel.addChangingListener(changedListener);
			beishuWheel.addScrollingListener(scrolledListener);
			beishuWheel.setCyclic(true);
			beishuWheel.setVisibleItems(5);
			beishuWheel.setInterpolator(new AnticipateOvershootInterpolator());

			zhuihaoWheel = (WheelView) beiTouZhuihaoDialog.findViewById(R.id.dialog_zhuihao_choose_wheel);
			zhuihaoWheel.setAdapter(new NumericWheelAdapter(zhuihaoNum));
			zhuihaoWheel.setCurrentItem(Integer.parseInt(zhuihaoEnd) - 1);
			zhuihaoWheel.addChangingListener(changedListener);
			zhuihaoWheel.addScrollingListener(scrolledListener);
			zhuihaoWheel.setCyclic(true);
			zhuihaoWheel.setVisibleItems(5);
			zhuihaoWheel.setInterpolator(new AnticipateOvershootInterpolator());
		}

		WindowManager.LayoutParams windowLp = beiTouZhuihaoDialog.getWindow().getAttributes();

		int[] location = new int[2];
		btnListClean.getLocationOnScreen(location);
		int totalTopHeight = location[1];
		EDebug.o(this, "total top height = " + totalTopHeight);
		int btnHeight = btnListClean.getHeight();
		EDebug.o(this, "btn Height  = " + btnHeight);
		int dialogHeight = windowLp.height;
		EDebug.o(this, "dialog Height = " + dialogHeight);
		int finalY = totalTopHeight + btnHeight - dialogHeight;
		EDebug.o(this, "finalY = " + finalY);

		windowLp.y = finalY;

		beiTouZhuihaoDialog.onWindowAttributesChanged(windowLp);

		beiTouZhuihaoDialog.show();

	}

	private OnWheelChangedListener changedListener = new OnWheelChangedListener() {

		@Override
		public void onChanged(WheelView wheel, int oldValue, int newValue) {
			if (!wheelScrolled) {
				updateStatus();
			}
		}
	};

	private OnWheelScrollListener scrolledListener = new OnWheelScrollListener() {

		@Override
		public void onScrollingStarted(WheelView wheel) {
			wheelScrolled = true;
		}

		@Override
		public void onScrollingFinished(WheelView wheel) {
			wheelScrolled = false;
			updateStatus();
		}

	};

	/**
	 * @Title: updateStatus
	 * @Description: 获取滚轮滑动到位置的数值
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void updateStatus() {
		beishuCurrent = beishuNum.get(beishuWheel.getCurrentItem() + 1);
		zhuihaoCurrent = zhuihaoNum.get(zhuihaoWheel.getCurrentItem() + 1);
		EDebug.o(ShuangseqiuChooseAct.this, "倍数" + beishuCurrent);
		EDebug.o(ShuangseqiuChooseAct.this, "追号" + zhuihaoCurrent);
	}

	/**
	 * @Title: showSubmitOrderDialog
	 * @Description: 显示提交订单的Dialog
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void showSubmitOrderDialog(String msg, String submit) {
		submitOrderDialog = new Dialog(ShuangseqiuChooseAct.this, R.style.dialog);
		submitOrderDialog.getWindow().setContentView(R.layout.dialog_quit);
		TextView tvDialogMsg = (TextView) submitOrderDialog.getWindow().findViewById(R.id.dialogquit_tv_msg);
		tvDialogMsg.setText(msg);
		btnSubmitOrder = (Button) submitOrderDialog.getWindow().findViewById(R.id.dialogquit_btn_submit);
		btnSubmitOrder.setText(submit);
		btnSubmitOrder.setOnClickListener(this);
		btnCancelOrder = (Button) submitOrderDialog.getWindow().findViewById(R.id.dialogquit_btn_cancel);
		btnCancelOrder.setOnClickListener(this);
	}

	/**
	 * @Title: initHandler
	 * @Description: 初始化Handler
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void initHandler() {
		handlerNormalBuy = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				// 购买成功
				case NORMALBUY_SUCCEED:
					buySucceed();
					ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().clear();
					break;
				// 购买失败
				case NORMALBUY_FAIL:
					if (shuangseqiuNormalBuyCommunicater.getState() == 0) {
						ViewerUtil.showTipDialog(ShuangseqiuChooseAct.this, shuangseqiuNormalBuyCommunicater.getErrorMSG() + Config.COMMA + Language.POPLOTTERYTIP_LOOKOVERRECORD, false);
					} else if (shuangseqiuNormalBuyCommunicater.getState() == 105) {
						popBalanceNotEnoughAlert();
					} else {
						// ViewerUtil.showTipDialog(ShuangseqiuChooseAct.this, shuangseqiuNormalBuyCommunicater.getErrorMSG(), false);
						Toast.makeText(ShuangseqiuChooseAct.this, shuangseqiuNormalBuyCommunicater.getErrorMSG(), 0).show();
					}
					break;
				// 连接失败
				case Config.CONNECTION_FAIL:

					// ViewerUtil.showTipDialog(ShuangseqiuChooseAct.this, Language.POPLOTTERYTIP_LOOKOVERRECORD, false);
					Toast.makeText(ShuangseqiuChooseAct.this, Language.POPLOTTERYTIP_LOOKOVERRECORD, 0).show();

					break;
				// 获取余额成功
				case GETBALANCE_SUCCEED:
					userCommunicater.updataUserInfo();
					isGetBalance = true;
					break;
				// 获取余额失败
				case GETBALANCE_FAIL:
					isGetBalance = true;
					break;
				// 获取期号列表成功
				case GET_EXPECT_LIST_SUCCEED:

					threadNormalBuy(expectCommuniacter.getTrackExceptionList());

					break;
				// 获取期号列表失败
				case GET_EXPECT_LIST_FAILED:

					// ViewerUtil.showTipDialog(ShuangseqiuChooseAct.this, Language.MSG_GETEXPECTLISTFAFAILED, false);
					Toast.makeText(ShuangseqiuChooseAct.this, Language.MSG_GETEXPECTLISTFAFAILED, 0).show();

					break;
				// 获取最新开奖号码成功
				case GET_LOTTERY_NUM_SUCCEED:
					lotteryNumInfo = currentLotteryNumCommunicater.getCurrentLotteryNum().get(0);
					String lastopencode = lotteryNumInfo.getLastopencode();
					if (lastopencode != null && !lastopencode.equals(Config.NULLMARK)) {
						String opencode[] = lastopencode.split("\\|");
						redcode = opencode[0].replace(Config.COMMA, Config.ONESPACE);
						bluecode = opencode[1];
						llLastLotteryNumProgress.setVisibility(View.GONE);
						llLastLotteryNum.setVisibility(View.VISIBLE);
						tvLastLotteryNumRed.setText(redcode);
						tvLastLotteryNumBlue.setText(bluecode);
					} else {
						llLastLotteryNumProgress.setVisibility(View.GONE);
						llLastLotteryNumShibai.setVisibility(View.VISIBLE);
					}
					break;
				// 获取最新开奖号码失败
				case GET_LOTTERY_NUM_FAILED:
					llLastLotteryNumShibai.setVisibility(View.VISIBLE);
					break;
				case DO_REFRESH:
					determineSetContentView();
					break;
				default:
					break;
				}
				progressdialogNormalbuy.dismiss();
			}
		};

	}

	/**
	 * @Title: threadGetExpectList
	 * @Description: 获取期号列表
	 * @param: @param startExpect
	 * @param: @param num 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void threadGetExpectList(final String startExpect, final String num) {

		new Thread() {

			@Override
			public void run() {

				super.run();
				Message msg;
				try {
					if (expectCommuniacter == null) {
						expectCommuniacter = new ShuangseqiuTraceExpectCommunicater();
					}
					boolean isGetSucceed = expectCommuniacter.isGetExpectSucceed(startExpect, num);
					if (isGetSucceed) {
						msg = handlerNormalBuy.obtainMessage(GET_EXPECT_LIST_SUCCEED, null);
					} else {
						msg = handlerNormalBuy.obtainMessage(GET_EXPECT_LIST_FAILED, null);
					}
					handlerNormalBuy.sendMessage(msg);
				} catch (Exception e) {

					msg = handlerNormalBuy.obtainMessage(Config.CONNECTION_FAIL, null);
					handlerNormalBuy.sendMessage(msg);
				}
			}
		}.start();

	}

	/**
	 * @Title: threadGetCurrentLotteryNum
	 * @Description: 获取当前开奖号码
	 * @param: @param lotid 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void threadGetCurrentLotteryNum(final String lotid) {
		new Thread() {

			@Override
			public void run() {
				super.run();
				Message msg;
				try {
					if (currentLotteryNumCommunicater == null) {
						currentLotteryNumCommunicater = new CurrentLotteryNumCommunicater();
					}
					boolean isGetLotteryNumSucceed = currentLotteryNumCommunicater.isGetCurrentLotteryNumSucceed(lotid);
					if (isGetLotteryNumSucceed) {
						msg = handlerNormalBuy.obtainMessage(GET_LOTTERY_NUM_SUCCEED, null);
					} else {
						msg = handlerNormalBuy.obtainMessage(GET_LOTTERY_NUM_FAILED, null);
					}
					handlerNormalBuy.sendMessage(msg);
				} catch (Exception e) {
					msg = handlerNormalBuy.obtainMessage(Config.CONNECTION_FAIL, null);
					handlerNormalBuy.sendMessage(msg);
				}

			}

		}.start();
	}

	/**
	 * @Title: threadNormalBuy
	 * @Description: 复式代购
	 * @param: @param expectList 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void threadNormalBuy(final String expectList) {

		new Thread() {
			@Override
			public void run() {
				super.run();
				try {
					if (shuangseqiuNormalBuyCommunicater == null) {
						shuangseqiuNormalBuyCommunicater = new ShuangseqiuNormalBuyCommunicater();
					}
					int buyzhuihao = Integer.parseInt(zhuihaoEnd);
					int buybeishu = Integer.parseInt(beishuEnd);
					int buymoney = betCountAll * buybeishu * buyzhuihao * 2;
					boolean isBuySucceed = shuangseqiuNormalBuyCommunicater.isBuySucceed(betCountAll, buybeishu, buyzhuihao, buymoney, isStopZhuihao, expectList);
					if (isBuySucceed) {
						Message msg = handlerNormalBuy.obtainMessage(NORMALBUY_SUCCEED, null);
						handlerNormalBuy.sendMessage(msg);
					} else {
						Message msg = handlerNormalBuy.obtainMessage(NORMALBUY_FAIL, null);
						handlerNormalBuy.sendMessage(msg);
					}
				} catch (Exception e) {

					Message msg = handlerNormalBuy.obtainMessage(Config.CONNECTION_FAIL, null);
					handlerNormalBuy.sendMessage(msg);
				}
			}
		}.start();
	}

	/**
	 * @Title: buySucceed
	 * @Description: 购买成功
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void buySucceed() {
		dialogBuySucceed = new Dialog(this, R.style.dialog);
		dialogBuySucceed.setContentView(R.layout.viewerutil_dialog_showbuysucceed);
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_msg)).setText(Language.MSG_BUYSUCCEED);
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_term)).setText(Language.MSG_BUYSHUANGSEQIU + ShuangseqiuInfo.getShuangseqiuInfo().getTermNum()
				+ Language.POPLOTTERYTIP_QI + betCountAll + Language.POPLOTTERYTIP_ZHU);
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_count)).setText(Language.MSG_ZHUIHAO + zhuihaoEnd + Language.POPLOTTERYTIP_QI);
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_cost)).setText(Language.MSG_RESULT_HEMAI_XIAOFEI + Language.POPLOTTERYTIP_RMB
				+ Integer.toString(betCountAll * Integer.parseInt(beishuEnd) * 2));
		((TextView) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_tv_balance)).setText(Language.MSG_RESULT_HEMAI_SHENGYUJINE + Language.POPLOTTERYTIP_RMB
				+ UserInfo.getUserInfo().getUserBalance());
		dialogBuySucceed.show();
		OnClickListener dialogSucceedListener = new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				switch (v.getId()) {
				case R.id.viewerutildialogshowbuysucceed_btn_back:
					dialogBuySucceed.dismiss();

					if (UserInfo.getUserInfo().isRebuy()) {
						if (ShuangseqiuChooseAct.this.getParent() != null) {
							ShuangseqiuChooseAct.this.getParent().finish();
							UserInfo.getUserInfo().setRebuy(false);
							return;
						}
					}
					ShuangseqiuChooseAct.showType = 2;
					UserInfo.getUserInfo().setRebuy(false);
					ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().clear();
					beishuEnd = Config.NUM1;
					zhuihaoEnd = Config.NUM1;
					tvListBeiShu.setText(beishuEnd);
					tvListZhuiHao.setText(zhuihaoEnd);
					setChooseview();

					break;

				case R.id.viewerutildialogshowbuysucceed_btn_toHall:
					dialogBuySucceed.dismiss();
					ShuangseqiuChooseAct.this.getParent().finish();
					ShuangseqiuChooseAct.showType = 1;
					break;

				default:
					break;
				}

			}
		};
		Button btnBc = (Button) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_btn_back);
		btnBc.setOnClickListener(dialogSucceedListener);
		if (UserInfo.getUserInfo().isRebuy()) {
			btnBc.setText(Language.MSG_FANHUIXIANGQING);
		}
		((Button) dialogBuySucceed.getWindow().findViewById(R.id.viewerutildialogshowbuysucceed_btn_toHall)).setOnClickListener(dialogSucceedListener);
		// dialogBuySucceed.setOnDismissListener(new OnDismissListener() {
		//
		// @Override
		// public void onDismiss(DialogInterface dialog) {
		// ShuangseqiuChooseAct.this.finish();
		// }
		// });

	}

	/**
	 * @Title: popBalanceNotEnoughAlert
	 * @Description: 用户金额不足提示
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void popBalanceNotEnoughAlert() {
		if (dialogBalanceNotEnough == null) {
			dialogBalanceNotEnough = new Dialog(this, R.style.dialog);
		}

		if (moneyNotEnoughListener == null) {
			moneyNotEnoughListener = new OnClickListener() {

				@Override
				public void onClick(View v) {
					switch (v.getId()) {
					case R.id.shiyixuanwu_alert_money_not_enough_btn_cancel:
						break;

					case R.id.shiyixuanwu_alert_money_not_enough_btn_recharge:
						UserInfo.getUserInfo().setBuyingRecharge(true);

						ShuangseqiuChooseAct.this.startActivity(new Intent().setClass(ShuangseqiuChooseAct.this, RechargeMenuPage.class));

						break;
					}

					dialogBalanceNotEnough.dismiss();
				}
			};
		}

		View view = this.getLayoutInflater().inflate(R.layout.shiyixuanwu_alert_money_not_enough, null);

		((Button) view.findViewById(R.id.shiyixuanwu_alert_money_not_enough_btn_cancel)).setOnClickListener(moneyNotEnoughListener);
		((Button) view.findViewById(R.id.shiyixuanwu_alert_money_not_enough_btn_recharge)).setOnClickListener(moneyNotEnoughListener);

		dialogBalanceNotEnough.setContentView(view);
		dialogBalanceNotEnough.show();
	}

	/**
	 * @Title: threadGetUserBalance
	 * @Description: 获取用户余额
	 * @param: 设定文件
	 * @return: void 返回类型
	 * 
	 */
	private void threadGetUserBalance() {
		new Thread() {
			@Override
			public void run() {
				super.run();
				try {
					Boolean b = userCommunicater.isLoginSucceed(UserInfo.getUserInfo().getUserName(), UserInfo.getUserInfo().getUserPwd());
					if (b) {
						Message msg = handlerNormalBuy.obtainMessage(GETBALANCE_SUCCEED, null);
						handlerNormalBuy.sendMessage(msg);
					} else {
						Message msg = handlerNormalBuy.obtainMessage(GETBALANCE_FAIL, null);
						handlerNormalBuy.sendMessage(msg);
					}
				} catch (Exception e) {
					Message msg = handlerNormalBuy.obtainMessage(GETBALANCE_FAIL, null);
					handlerNormalBuy.sendMessage(msg);

				}
			}
		}.start();
	}

	/**
	 * @Title: topHeight
	 * @Description: 计算手机屏幕上边提示栏的高度
	 * @param: @param context
	 * @param: @return 设定文件
	 * @return: int 返回类型
	 * @throws
	 */
	private int getTopHeight() {
		int topBarHeight = 0;
		Rect rect = new Rect();
		getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
		topBarHeight = rect.top;
		EDebug.o("rect.height()" + rect.height() + "rect.top" + rect.top);
		return topBarHeight;
	}

}
